<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CouponServiceType extends Model {

    public $timestamps = false;

    protected $table = 'coupon_service_type';



    /**
     * @param int $coupon_id
     * @param array $service_type
     * @return bool
     */
    public function setData(int $coupon_id, array $service_type)
    {

        $re_del       = $this->where('coupon_id', $coupon_id)->delete();
        $service_type = array_filter($service_type);
        if($service_type) {
            $insert_data = [];
            foreach ($service_type as $service_type_id) {
                $insert_data[] = [
                    'coupon_id'       => $coupon_id,
                    'service_type_id' => $service_type_id,
                ];
            }
            $re_insert = $this->insert($insert_data);
        }
        return true;

    }

}
